package com.sicheng.lc.周赛.分类.模拟;

import com.sicheng.algorithm.node.ListNode;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/5 11:00
 */
public class 链表最大孪生和 {
    //https://leetcode.cn/problems/maximum-twin-sum-of-a-linked-list/
    static int[] nums = new int[(int) 1e5];

    public int pairSum(ListNode head) {
        int t = 0;
        while (head != null) {
            nums[t++] = head.val;
            head = head.next;
        }
        int max = -1;
        for (int i = 0; i <= t / 2 - 1; i++) {
            max = Math.max(nums[i] + nums[t - 1 - i], max);
        }
        return max;
    }
}
